﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using CloudClip.ExtensionMethod;

namespace CloudClip
{
    public class Setting
    {
        public string UserName { get; set; }
        public string UserPassword { get; set; }
        public bool AutoLogin { get; set; }

        public string LoginTypeString { get; set; }
        public string ClipFolderPath { get; set; }

        public void SaveSetting()
        {
            using (StreamWriter streamWriter = new StreamWriter(SettingHelper.SettingPath))
            {
                streamWriter.Write(this.ToXML());
            }
        }
    }

    public  class SettingHelper
    {
        public static string SettingPath = 
            Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"setting.xml");

        public static Setting GetSetting()
        {
            if (SettingPath.CheckFileExist() == false)
                return null;

            Setting setting = null;

            using (StreamReader streamReader = new StreamReader(SettingPath))
            {
                string sXML = streamReader.ReadToEnd();

                setting = XMLExtension.FromXML<Setting>(sXML);
            }

            return setting;
        }
    }
}
